#ifndef     GAMEOBJECT_H_
# define    GAMEOBJECT_H_

# include "vector.h"
# include "IMap.h"
# include "Graphics/MainGraphic.h"
# include "Graphics/GraphicComponent.h"

class IMap;

class GameObject
{
public:
    static MainGraphic * mg;

public:
    enum direction { NONE = 0, LEFT = 1, RIGHT = 2, UP = 4, DOWN = 8 }; // 0000, 0001, 0010, 0100, 1000
    enum objtype { BASE, MOBILE, BULLET };

public:
    virtual objtype type() { return BASE; }

public:
    GameObject()
        : _gc(*mg), _active(true), _pos(50,50), _vel(0,0), _size(32, 44), _dir(GameObject::RIGHT), _collide(NONE) {}
    GameObject(vector const & pos, vector const & vel, vector const & size, GameObject::direction const dir = GameObject::RIGHT)
        : _gc(*mg), _active(true), _pos(pos), _vel(vel), _size(size), _dir(dir), _collide(NONE) {}
    GameObject(GameObject const & oth)
        : _gc(*mg), _active(true), _pos(oth._pos), _vel(oth._vel), _size(oth._size), _dir(oth._dir), _collide(oth._collide) {}
    ~GameObject() {}

    virtual void update(float elapsedTime, IMap const & map);
    virtual void checkCollision(GameObject & oth, float const elapsedTime);
    virtual void onHit() {}

    vector & getPosition() { return _pos; }
    vector const & getPosition() const { return _pos; }
    vector const & getSize() const { return _size; }
    vector const & getVelocity() const { return _vel; }
    direction const getDir() const { return _dir; }
    int const getCollision() const { return _collide; }
    bool isActive() const { return _active; }

    bool operator<(GameObject const & oth) const;

    vector getDownRight() const;

    void setGraphicComponent(std::string const & img, vector const & subrect = vector());

protected:
    GraphicComponent _gc;
    bool             _active;
    vector           _pos;
    vector           _vel;
    vector           _size;
    direction        _dir;
    char             _collide;
};

#endif   /* GAMEOBJECT_H_ */
